﻿using AutoMapper;
using BasehInfoManagerModel;
using BasehInfoManagerViewModel;
using BaseInfoManagerBll;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace zy_11._10.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BasehInfoManagerController : ControllerBase
    {

        private ModuleDbBll _moduleDbBll;
        private IMapper _mapper;

        public BasehInfoManagerController(ModuleDbBll moduleDbBll, IMapper mapper)
        {
            _moduleDbBll = moduleDbBll;
            _mapper = mapper;
        }

        //显示级别
        [HttpGet]
        public List<ModuleDb> GetModuleDbsAll()
        {
            return _moduleDbBll.GetModuleDbsAll();
        }
        [HttpGet]
        public List<ModuleDbView> GetModuleDbViewsAll()
        {
            return _moduleDbBll.GetModuleDbViewsAll();
        }

        //添加
        [HttpGet]
        public bool VModuleCode(string mc)
        {
            return _moduleDbBll.VModuleCode(mc);
        }
        [HttpPost]

        //添加
        public bool ModuleAdd(ModuleDbView view)
        {
            if (string.IsNullOrWhiteSpace(view.module_code))
            {
                return false;
            }
            if (!_moduleDbBll.VModuleCode(view.module_code))
            {
                return false;
            }
            ModuleDb dbModel = _mapper.Map<ModuleDb>(view);
            dbModel.creator_date = DateTime.Now;
            dbModel.creator_name = "创建人姓名";
            return _moduleDbBll.ModuleAdd(dbModel);
        }

        //修改
        [HttpPost]
        public bool ModuleUpdate(ModuleDbView view)
        {
            if (string.IsNullOrWhiteSpace(view.module_code))
            {
                return false;
            }
            ModuleDb dbModel = _mapper.Map<ModuleDb>(view);
            dbModel.modifi_date = DateTime.Now;
            dbModel.modifi_name = "创建人姓名";
            return _moduleDbBll.ModuleUpdate(dbModel);
        }
        //详情
        [HttpGet]
        public ModuleDbView GetMViewByCode(string code)
        {
            if (string.IsNullOrWhiteSpace(code))
            {
                return null;
            }
            return _moduleDbBll.GetModuleDbViewByCode(code);

        }

        //查找
        [HttpGet]
        public ModuleDbView GetModuleDbViewByCodeSonSql(string moduleCode)
        {
            return _moduleDbBll.GetModuleDbViewByCodeSonSql(moduleCode);
        }

    }
}
